<?php

class BlgCodeStack{
	protected $stack;
	protected $type;
	
	function __construct($type= NULL){
		$this->stack= array();
		$this->type= $type;
	}
	
	public function append($code){
		$this->stack[]= $code;
	}
	
	public function code($htmltags= FALSE){
		if(empty($this->stack))
			return '';
		
		$str= '';
		if(FALSE!==$htmltags){
			switch($this->type){
				case 'js': $str= '<script language="javascript">'."\n"; break;			
			}
		}		
		
		$str.= implode("\n\r", $this->stack);
		
		if(FALSE!==$htmltags){
			switch($this->type){
				case 'js': $str.= "\n\t".'</script>'; break;			
			}
		}	

		return $str;
	}
	
	public function __toString(){
		echo $this->code();
	} 
}